<?php

namespace App\Http\Resources;

use App\Http\Responses\Resource;

class Chapter extends Resource
{


    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request
     * @return array
     */
    public function toArray($request)
    {

        $schedule_at = $this->getScheduleAt();


        return [

            'id' => $this->id,
            'chapter_num' => $this->chapter_num,
            'name' => $this->name,
            'create_time' => $this->create_time,
            'last_modify_time' =>  $this->last_modify_time,
            'type' => $this->type,
            'status' => $this->status,
            'publish_schedule_at' => $this->when($schedule_at,$schedule_at)

        ];

    }


    protected function getScheduleAt(){

        $schedule = $this->schedule;

        if (empty($schedule)){
            return null;
        }

        return $schedule->schedule_at;

    }
}
